-- attrib_damage
-- create by zhuangsl
-- 单体伤害，根据专属技能消耗的属性计算伤害
-- 配置：attrib_damage(slime_skill_id, attrib, force)

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 专属技能等级
        local slimeSkillId = para[1];
        local level;
        extra = extra or {};
        if extra["level"] then
            level = tonumber(extra["level"]);
        else
            local prop = PropM.combine(source, "gain_slime_skill", para[1]);
            level = PropM.apply(prop, 0);
        end

        -- 专属技的消耗
        local energy = SlimeSkillM.query(slimeSkillId, "energy");
        local dbase = SlimeSkillM.query(slimeSkillId, "dbase");
        local cost = energy[para[2]] or 0;
        if type(dbase["changeable_cost"]) == 'string' then
            -- 消耗值会变化，用公式计算
            cost = FormulaM.invoke(dbase["changeable_cost"]);
        end

        -- 伤害
        local force = para[3];
        local damage = math.modf(cost * (1000 + force * level) / 1000);

        -- 斯巴达专属加成
        local prop = PropM.combine(source, "battle_cry", 1);
        if prop[3] > 0 then
            -- 触发特技发动事件
            EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        end
        damage = PropM.apply(prop, damage);

        -- 使用探索点，抛出播放特效事件
        if para[2] == "search_point" and target.type == OBJECT_TYPE_MONSTER then
            EventMgr.fire(event.SEARCH_POINT_DAMAGE, { ["pos_list"] = {target:getOwner(),}, });
        end

        if SkillM.immunitySkill(source, target, skillId) then
            -- 目标有免疫专属技属性
            if not SkillM.getSequence(target) then
                SkillM.initSequence(source, target, skillId);
            end
            SkillM.getSequence(target):immunity(source, target, skillId);
        else
            -- 增加命中动作
            SkillM.getSequence(target):hit(source, target, skillId);
            -- 伤害
            CombatM.doDamage(source, target, damage, skillId, nil, extra);
        end

        -- 作用目标
        return target;
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), arr[2], tonumber(arr[3]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 专属技能等级
        local prop = PropM.combine(source, "gain_slime_skill", para[1]);
        local level = PropM.apply(prop, 0);

        -- 专属技的消耗
        local energy = SlimeSkillM.query(para[1], "energy");
        local dbase = SlimeSkillM.query(para[1], "dbase");
        local cost = energy[para[2]] or 0;
        if type(dbase["changeable_cost"]) == 'string' then
            -- 消耗值会变化，用公式计算
            cost = FormulaM.invoke(dbase["changeable_cost"]);
        end

        -- 伤害
        local force = para[3];

        local damage = math.modf(cost * (1000 + force * level) / 1000);

        -- 斯巴达专属加成
        prop = PropM.combine(source, "battle_cry", 1);
        damage = PropM.apply(prop, damage);

        desc = string.gsub(desc, "{attrib_damage}", damage);
        desc = string.gsub(desc, "{attrib_cost}", cost);

        return desc;
    end,
};
